//获取应用实例
const app = getApp()
Page({
  data: {
    pickerHidden: true,
    chosen: '',
    modalHidden: true,
    name: '',
    gender: '',
    age: '',
    technology: '',
    isPublic: '',
    lists:[],
    popErrorMsg:''
  },
  onLoad: function (options) {
    var that = this;
    wx.request({
      url: 'https://mingpingqiang.top/mpq/app/getReason',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        var dd = res.data.data;
        that.setData({
          lists:dd,
        })
      }
    })
  },
  formSubmit: function (e) {
    var openid = app.globalData.openid;
    var value = e.detail.value;
    value.openid = openid;
    console.log(value);
    var name = value.name;
    var gender = value.gender;
    var age = value.age;
    var technology = value.technology;
    var reason = value.reason;
    var education = value.education;
    var warn = "";//弹框时提示的内容  
    var flag = true;//判断信息输入是否完整 
    if (name == "") {
      warn = "请填写您的姓名！";
    } else if (gender == "") {
      warn = "请选择您的性别！";
    } else if (education == "") {
      warn = "请填写您的学历！";
    } else if (age == "") {
      warn = "请填写您的年龄！";
    }else if (technology == "" && reason=="") {
      warn = "请填写您的理由！";
    }else{
      flag = false;
      wx.showModal({
        title: '您填写的表单如下',
        content: '姓名:' + name
        + '\r\n性别：' + gender
        + '\r\n学历：' + education
        + '\r\n年龄：' + age
        + '\r\n为什么想了解小玉：' + technology,
        showCancel: true,
        cancelText: "否",
        confirmText: "是",
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
            wx.request({
              url: 'https://mingpingqiang.top/mpq/app/saveReason',
              data: value,
              header: {
                'content-type': 'application/json'
              },
              success: function (res) {
                var dd = res.data.data;
                console.log(dd)
              }
            })
            wx.navigateTo({
              url: '../synopsis/synopsis'
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      });
    }
    if (flag) {
      wx.showModal({
        title: '提示',
        content: warn
      }) 
    } 
  },
  formReset: function (e) {
    console.log('form发生了reset事件，携带数据为：', e.detail.value)
    wx.navigateTo({
      url: '../index/index'
      })
  },
  modalChange: function (e) {
    this.setData({
      modalHidden: true
    })
  },
  ohShitfadeOut: function() {
    var fadeOutTimeout = setTimeout(() => {
      this.setData({ popErrorMsg: '' });
      clearTimeout(fadeOutTimeout);
    }, 3000);
  }, 
})